#ifndef DISPATCHER_HH
#define DISPATCHER_HH

#include "../library/thread.hh"
#include "../library/mutex.hh"
#include "../library/socket.hh"
#include "../library/protocol.hh"

#include "serverhandler.hh"

#include <list>
#include <iostream>
#include <time.h>

using namespace std;
using namespace NM;

class Dispatcher : Thread, Mutex
{
private: // variables
    bool                    _run;                       // Mutex protected / used to stop main thread
    Socket                  _localNetwork;
    list<ServerHandler*>    _servers;

private: // main thread variables

public: // interface
    Dispatcher();
    Dispatcher(string address, int port);
    void Start(list<ServerHandler*> servers);
    void Stop();

    void loop();                                        // Thread execution

private: // internals
    bool init();
    bool isRunning();
    void setRunning(bool run);
};

void *dispatcher_starter(void *data);

#endif // DISPATCHER_HH
